package org.scut.smartgeometry.act.adapter;

import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.ImageView;

import org.scut.smartgeometry.R;


/**
 * Created by Administrator on 13-6-28.
 */
public class GridImageAdapter extends ArrayAdapter<Drawable> {

    private GridView gridView;

    public GridImageAdapter(Context context, Drawable[] drawables, GridView gridView) {
        super(context, 0, drawables);
        this.gridView = gridView;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ImageView view = null;

        Drawable drawable = getItem(position);

        if(convertView == null){
            view = new ImageView(getContext());
            int width = WallpaperManager.getInstance(getContext()).getDesiredMinimumWidth();
            int height = WallpaperManager.getInstance(getContext()).getDesiredMinimumHeight();
            view.setLayoutParams(new GridView.LayoutParams(width/4, height/4));
            view.setScaleType(ImageView.ScaleType.FIT_CENTER);
        }
        else{
            view = (ImageView) convertView;
        }

        view.setImageDrawable(drawable);

        return view;
    }
}
